#pragma once
#include "../third/include/aip-cpp-sdk/speech.h"
#include "logger.hpp"

namespace im{
    /*
    *  百度语音识别api技术文档：https://ai.baidu.com/ai-doc/SPEECH/dlbxfrs5o
    */
    class ASRClient{
    public:
        using ptr = std::shared_ptr<ASRClient>; 
        ASRClient(const std::string& id, const std::string& key, const std::string& secret)
            :_client(aip::Speech(id, key, secret)){}

        bool recogize(const std::string& data, std::string& result){
            auto res = _client.recognize(data, "pcm", 16000, aip::null);
            if(res["err_no"] == 0){
                result = res["result"][0].asString();
                return true;
            }else{
                result = res["err_msg"].asString();
                LOG_CRITICAL("语音识别失败:{}", res["err_msg"].asString());
                return false;
            }
        }
    private:
        aip::Speech _client;
    };
}